package cn.wolfcode.wolf2w.service.impl;

import cn.wolfcode.wolf2w.domain.ScenicSpot;
import cn.wolfcode.wolf2w.repository.ScenicSpotMongoRepository;
import cn.wolfcode.wolf2w.service.IScenicSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScenicSpotServiceImpl implements IScenicSpotService {

    @Autowired
    private ScenicSpotMongoRepository repository;
    @Autowired
    private MongoTemplate template;

    @Override
    public void save(ScenicSpot scenicSpot) {
        scenicSpot.setId(null);
        repository.save(scenicSpot);
    }

    @Override
    public void delete(String id) {
        repository.deleteById(id);
    }

    @Override
    public void update(ScenicSpot scenicSpot) {
        repository.save(scenicSpot);
    }

    @Override
    public ScenicSpot find(String id) {
        ScenicSpot scenicSpot = repository.findById(id).orElse(null);

        return scenicSpot;
    }

    @Override
    public List<ScenicSpot> findAll() {
        List<ScenicSpot> list = repository.findAll();
        return list;
    }
}
